<?php

use app\components\BasePager;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

/* @var $book */
/* @var $dataProvider ActiveDataProvider */
$items = $dataProvider->getModels();
?>
<div class="panel book-comment">
    <div class="panel-header"><h4>哈友吐槽</h4></div>
    <div class="panel-body">
        <div class="comment-form">
            <?= Html::beginForm(['comic/comment']); ?>
            <?= Html::hiddenInput('book_id', $book['id']); ?>
            <?= Html::hiddenInput('parent_id', 0); ?>

            <div class="form-group">
                <?= Html::textarea('content', '', ['class' => 'form-input', 'rows' => 4, 'placeholder' => '吐槽']); ?>
            </div>
            <div class="form-group">
                <div class="text-right">
                    <?= Html::submitButton('吐个槽', ['class' => 'btn btn-lg btn-danger comment-submit']); ?>
                </div>
            </div>
            <?= Html::endForm(); ?>
        </div>
        <div class="comment-list">
            <?php foreach ($items as $k => $item): ?>
                <div class="comment tile" id="<?= $item['id']; ?>">
                    <div class="tile-icon mr-2">
                        <img class="avatar avatar-lg" src="<?= $item->user->getAvatar(); ?>" alt="...">
                    </div>
                    <div class="tile-content">
                        <div class="tile-title">
                            <span class="author text-bold mr-4"><?= ArrayHelper::getValue($item['user'], 'username'); ?></span>
                            <span class="date"><?= Yii::$app->formatter->asRelativeTime($item['create_time']); ?></span>
                        </div>
                        <p class="tile-subtitle"><?= Html::encode($item['content']); ?></p>
                    </div>
                    <div class="tile-action">
                        <a class="reply hover" href="javascript:void(0);">回复</a>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
        <?php if($dataProvider->getPagination()->getPageCount() > 1): ?>
            <div class="comment-pagination pt-4">
                <?= BasePager::widget(['pagination' => $dataProvider->getPagination()]); ?>
            </div>
        <?php endif; ?>
    </div>

</div>